package main

import (
	"context"
	"fmt"
	"time"
)

func main() {
	//WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).

	bg := context.Background()

	//ctx , cancel := context.WithTimeout(bg, 100 * time.Microsecond)
	ctx, cancel := context.WithDeadline(bg, time.Now().Add(100*time.Microsecond))

	defer cancel()
	select {
	case <-ctx.Done():
		fmt.Println(ctx.Err())
	case <-time.After(1 * time.Second):
		fmt.Println("overslept")
	}
	//context deadline exceeded
}
